﻿using GMap.NET.WindowsForms.Markers;
using GMap.NET.WindowsForms;
using GMap.NET;

using FLEN_Sim.Properties;
using FLEN_Sim.config;


namespace FLEN_Sim.gui.map
{
    /// <summary>
    /// Stellt verschiedene Marker-Typen bereit.
    /// </summary>
    public class MapMarkers
    {
        /// <summary>
        /// Marker für ein Krankenhaus.
        /// </summary>
        public class HospitalMarker : GMapMarker
        {
            /// <summary>
            /// Standard-Konstruktor.
            /// </summary>
            /// <param name="p">Der PointLatLng auf der Karte, auf dem der Marker platziert werden soll.</param>
            public HospitalMarker(GMap.NET.PointLatLng p) : base(p)
            {
                this.Size = Resources.marker_hosp.Size;
            }

            public override void OnRender(System.Drawing.Graphics g)
            {
                g.DrawImage(Resources.marker_hosp, System.Convert.ToInt32(LocalPosition.X - Size.Width / 2), System.Convert.ToInt32(LocalPosition.Y - Size.Height / 2), Size.Width, Size.Height);
            }
        }

        /// <summary>
        /// Marker für eine Rettungswache.
        /// </summary>
        public class AmbulanceStationMarker : GMapMarker
        {
            public const int STATE_IN = 1;
            public const int STATE_ALLOUT = 2;
            public const int STATE_OUTOFTIME = 3;

            private int state;

            /// <summary>
            /// Standard-Konstruktor.
            /// </summary>
            /// <param name="p">Der PointLatLng auf der Karte, auf dem der Marker platziert werden soll.</param>
            /// <param name="State">Der Status der Rettungswache - AmbulanceStationMarker.STATE_* für richtigen Status.</param>
            public AmbulanceStationMarker(GMap.NET.PointLatLng p, int State)
                : base(p)
            {
                this.Size = Resources.home_green.Size;
                state = State;
            }

            public override void OnRender(System.Drawing.Graphics g)
            {
                switch (state)
                {
                    case AmbulanceStationMarker.STATE_IN:
                        g.DrawImage(Resources.home_green, System.Convert.ToInt32(LocalPosition.X - Size.Width / 2), System.Convert.ToInt32(LocalPosition.Y - Size.Height / 2), Size.Width, Size.Height);
                        break;
                    case AmbulanceStationMarker.STATE_ALLOUT:
                        g.DrawImage(Resources.home_red, System.Convert.ToInt32(LocalPosition.X - Size.Width / 2), System.Convert.ToInt32(LocalPosition.Y - Size.Height / 2), Size.Width, Size.Height);
                        break;
                    case AmbulanceStationMarker.STATE_OUTOFTIME:
                        g.DrawImage(Resources.home_grey, System.Convert.ToInt32(LocalPosition.X - Size.Width / 2), System.Convert.ToInt32(LocalPosition.Y - Size.Height / 2), Size.Width, Size.Height);
                        break;
                }                
            }

            public int State
            {
                get
                {
                    return state;
                }
                set
                {
                    if ((value > 0 && value < 4))
                    {
                        state = value;

                        if (Config.CONTROL.InvokeRequired)
                        {
                            RefreshControl rc = new RefreshControl(Config.CONTROL.Refresh);
                            Config.CONTROL.Invoke(rc);
                        }
                        else
                        {
                            Config.CONTROL.Refresh();
                        }
                    }
                    else
                        throw new System.ArgumentException("State must be an Integer between 1 and 3 - use static AmbulanceStationMarker.STATE_*");
                }
            }

            private delegate void RefreshControl();
        }

        public class EmergencyMarker : GMapMarker
        {
            public const int VEHICLE_ARRIVED = 1;
            public const int VEHICLE_NOT_ARRIVED = 2;

            private int state;

            public EmergencyMarker(GMap.NET.PointLatLng p)
                : base(p)
            {
                this.Size = Resources.pin_green.Size;
                state = EmergencyMarker.VEHICLE_NOT_ARRIVED;
            }

            public override void OnRender(System.Drawing.Graphics g)
            {
                switch (state)
                {
                    case EmergencyMarker.VEHICLE_ARRIVED:
                        g.DrawImage(Resources.pin_green, System.Convert.ToInt32(LocalPosition.X - Size.Width / 2), System.Convert.ToInt32(LocalPosition.Y - Size.Height / 2), Size.Width, Size.Height);
                        break;
                    case EmergencyMarker.VEHICLE_NOT_ARRIVED:
                        g.DrawImage(Resources.pin_red, System.Convert.ToInt32(LocalPosition.X - Size.Width / 2), System.Convert.ToInt32(LocalPosition.Y - Size.Height / 2), Size.Width, Size.Height);
                        break;
                }                
            }

            public int State
            {
                get
                {
                    return state;
                }
                set
                {
                    if ((value > 0 && value < 3))
                    {
                        state = value;
                        Config.CONTROL.Refresh();
                    }
                    else
                        throw new System.ArgumentException("State must be an Integer between 1 and 2 - use static EmergencyMarker.STATE_*");
                }
            }
        }

        public class AmbulanceVehicleMarker : GMapMarker
        {
            /// <summary>
            /// Standard-Konstruktor.
            /// </summary>
            /// <param name="p">Der PointLatLng auf der Karte, auf dem der Marker platziert werden soll.</param>
            public AmbulanceVehicleMarker(GMap.NET.PointLatLng p)
                : base(p)
            {
                this.Size = Resources.helicopter_yellow.Size;
            }

            public override void OnRender(System.Drawing.Graphics g)
            {
                g.DrawImage(Resources.helicopter_yellow, System.Convert.ToInt32(LocalPosition.X - Size.Width / 2), System.Convert.ToInt32(LocalPosition.Y - Size.Height / 2), Size.Width, Size.Height);
            }
        }
    }
}
